<?php
class Admin_Template_Email_Controller extends Admin_Controller {

    public $restful = true;

    public function __construct()
    {
        parent::__construct();
        //--Your Code --//
        $this->theme->set_theme("admin") ;
        $this->theme->set_layout("default") ;
    }


    public function get_template(){
    	if (Auth::guest()) return Redirect::to('admin/login');
    	 
    	if (!Auth::check())
    	{
    		return Redirect::to('admin/login');
    	}else{
        $data['template'] = DB::table('emailtemplate')->get();

        $this->theme->title("Email Template");
        return $this->theme->render('admin::template.email',$data);
    }
    }

    public function post_template(){



        if (Input::get('btn') == 'save') {

            $rules = array(

                'description' => 'required',

            );

            $validator = Validator::make(Input::get(), $rules);

            $thisOrderID = Input::get('tmpID');



            if( $validator->fails() )
            {
                return Redirect::back()->with_input()->with_errors($validator)->with('message','Invalid Operation !');
            }
            else
            {
                /*Update Query : update Location info : by rahul(20/10/14) */
                $categories =DB::table('emailtemplate')
                    ->where('id', '=', $thisOrderID)
                    ->update(array(
                            'description' => Input::get('description'),

                        )
                    );



                //return Redirect::to('admin/home/child/'.Input::get('parent_id'));
                return Redirect::back()->with('message','Data Successfully updated !');
            }

        }else{
            $data['template'] = DB::table('emailtemplate')->get();
            if(Input::get('email_tempalte')){

                $templateid = Input::get('email_tempalte');



                $p = DB::table('emailtemplate')->where('id','=',$templateid)->first();

                $data['tmp']['info'] = $p;

                $this->theme->title("Email Template");
                return $this->theme->render('admin::template.email',$data);


            }else{
                return Redirect::back()->with('message','Invalid Input');

            }
        }
    }





}